<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Magin&Padding</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      list-style: none;
    }
    .margin,.padding{
      margin: 50px auto;
      position: relative;
      width: 500px;
      height: 300px;
      border: 1px solid gray;
      display: flex;
      flex-direction: column;
    }
    /* .margin>div:nth-child(1){ */
    /* .margin>div{
      margin: auto;
    } */
    .margin>div{
      margin: 10px 0;
    }
    .margin>div:nth-child(2){
      margin-left: 10px;
    }
    .margin>div, .padding>div{
      width: 300px;
      height: 50px;
      border: 1px solid red;
    }
    .padding>div:nth-child(2){
      padding: 0 0 10px 10px;
      background-color: gray;
    }
  </style>
</head>
<body>
  <div class="margin">
    <div>flex布局下相邻元素margin不会折叠</div>
    <div></div>
    <div></div>
  </div>
  <div class="padding">
    <div></div>
    <div></div>
    <div></div>
  </div>
</body>
</html>